<#attempt>
<form action="${ctx}/company/systemForm" method="post" id="addCompany" enctype="multipart/form-data">
		<input type="hidden" name="companyId" value="${company.companyId!}" />
		<input type="hidden" name="userId" value="${user.userId!}" />
		<div class="form-group form-inline row">
			<div class="col-sm-6">
				<label><span style="color: red">*</span>公司名称：</label>
				<input class="form-control" type="text" name="companyName" value="${company.companyName!}" maxlength="100" required />
			</div>
			<div class="col-sm-6">
				<label><span style="color: red">*</span>公司简称：</label>
				<input class="form-control" type="text" name="shortName" value="${company.shortName!}" maxlength="50" required />
			</div>
		</div>
		<div class="form-group form-inline row">
			<div class="col-sm-6">
				<div style="display: inline-block;">
					<label><span style="color: red">*</span>所属地区：</label>
					<select class="form-control select2" name="provinceCode"  style="width: 120px;" >
						<option value="">--请选择--</option>
						<#list firstLevel as a>
							<option value="${a.code}" <#if company.provinceCode?? && a.code==company.provinceCode>selected</#if> >${a.city}</option>
						</#list>
					</select>
				</div>
				<select class="form-control select2" name="cityCode" id="cityCode" style="width: 120px" required>
					<option value="">--请选择--</option>
					<#if secondLevel??>
						<#list secondLevel as a>
							<option value="${a.code}" <#if company.cityCode?? && a.code==company.cityCode>selected</#if> >${a.city}</option>
						</#list>
					</#if>
				</select>
			</div>
			<div class="col-sm-6">
				<label><span style="color: red">*</span>所属行业:</label>
				<select class="form-control width180" name="industryId"  required>
					<option value="">--请选择--</option>
					<#list industryMap as key,value>
						<option value="${key}" <#if company.industryId?? && key == company.industryId?c>selected</#if> >${value}</option>
					</#list>
				</select>
			</div>
		</div>
		<div class="form-group form-inline row">
			<div class="col-sm-6 col-select179-box">
				<label>销售：</label>
				<select class="form-control select2" name="saleId">
					<option value="">--请选择--</option>
					<#list saleManagers as sale>
						<option value="${sale.id!}" <#if company.saleId?? && sale.id == company.saleId>selected</#if> >${sale.nickName!}</option>
					</#list>
				</select>
				<input class="form-control" type="hidden" name="saleName" value="${company.saleName!}" />
			</div>
			<div class="col-sm-6 col-select179-box">
				<label>客户经理：</label>
				<select class="form-control select2" name="accountManagerId">
					<option value="-1">--请选择--</option>
					<#list accountManages as accountManage>
						<option value="${accountManage.id!}" <#if company.accountManagerId?? && accountManage.id == company.accountManagerId>selected</#if> >${accountManage.nickName!}</option>
					</#list>
				</select>
				<input class="form-control" type="hidden" name="accountManagerName" value="${company.accountManagerName!}" />
			</div>
		</div>
		<div class="form-group form-inline row">
			<div class="col-sm-6 col-select179-box">
				<label><span style="color: red">*</span>代理商：</label>
				<select class="form-control select2" name="agentsId" required>
					<option value="">--请选择--</option>
					<#if agents?? && (agents?size > 0)>
						<#list agents as u>
	                       <option value="${u.id}" <#if company.agentsId?? && u.id==company.agentsId>selected</#if> >${u.nickName!}</option>
	                   </#list>
                   </#if>
				</select>
				<input type="hidden" name="agentsName" value="${company.agentsName!}" />
			</div>
			<div class="col-sm-6">
				<label>公司软交换：</label>
				<#if company.newSoftSwitch??>
					<input type="hidden" name="newSoftSwitch" value="${company.newSoftSwitch}" />
					<#list softswitchMap as k, v>
						<#if (company.newSoftSwitch?c == k)>
							<input class="form-control" type="text" value="${v}" readonly="readonly" />
							<#break>
						</#if>
					</#list>
				<#else>
					<input type="hidden" name="newSoftSwitch" value="0"/>
					<input class="form-control" type="text" value="三汇" readonly="readonly" />
				</#if>
			</div>
		</div>
		<div class="form-group form-inline row">
			<div class="col-sm-6">
				<label>启用状态：</label>
				<#if company.enableStatus??>
					<label class="radio-inline"><input type="radio" class="minimal" name="enableStatus"  value="1" <#if company?? && company.enableStatus?? && company.enableStatus = 1>checked</#if> >&nbsp;&nbsp;启用</label>
					<label class="radio-inline"><input type="radio" class="minimal" name="enableStatus"  value="0" <#if company?? && company.enableStatus?? && company.enableStatus = 0>checked</#if> >&nbsp;&nbsp;停用</label>
				<#else>
					<label class="radio-inline"><input type="radio" class="minimal" name="enableStatus"  value="1" checked >&nbsp;&nbsp;启用</label>
					<label class="radio-inline"><input type="radio" class="minimal" name="enableStatus"  value="0" >&nbsp;&nbsp;停用</label>
				</#if>
			</div>
			<div class="col-sm-6">
				<label>客户级别:</label>
				<select class="form-control width180" name="customerLevel">
					<option value="">--请选择--</option>
					<#list customerLevelMap as k,v>
						<option value="${k}" <#if company.customerLevel?? && k==company.customerLevel>selected</#if>>${v}</option>
					</#list>
				</select>
			</div>
		</div>
		
		<h4 style="padding: 20px 0;border-bottom: 1px solid #e5e5e5">功能授权：</h4>
		<div class="form-group form-inline row">
			<div class="col-sm-6">
				<label>打断：</label>
				<label class="radio-inline"><input type="radio" class="minimal" name="interrupt" value="0" <#if company?? && company.interrupt?? && company.interrupt = 0>checked</#if>>&nbsp;&nbsp;不启用</label>
				<label class="radio-inline"><input type="radio" class="minimal" name="interrupt" value="1" <#if company?? && company.interrupt?? && company.interrupt = 1>checked</#if>>&nbsp;&nbsp;启用</label>
			</div>
			<div class="col-sm-6">
				<label>转坐席：</label>
				<label class="radio-inline"><input type="radio" class="minimal" name="turnReclined" value="0" <#if company?? && company.turnReclined?? && company.turnReclined = 0>checked</#if>>&nbsp;&nbsp;不启用</label>
				<label class="radio-inline"><input type="radio" class="minimal" name="turnReclined" value="1" <#if company?? && company.turnReclined?? && company.turnReclined = 1>checked</#if>>&nbsp;&nbsp;启用</label>
			</div>
		</div>
		<div class="form-group form-inline row">
			<div class="col-sm-6">
				<label>号码隐藏：</label>
				<label class="radio-inline"><input type="radio" class="minimal" name="hidePhone" value="0" <#if user?? && user.hidePhone?? && user.hidePhone = 0>checked</#if>>&nbsp;&nbsp;不隐藏</label>
				<label class="radio-inline"><input type="radio" class="minimal" name="hidePhone" value="1" <#if user?? && user.hidePhone?? && user.hidePhone = 1>checked</#if>>&nbsp;&nbsp;隐藏</label>
			</div>
			<div class="col-sm-6">
				<label>导入号码限制：</label>
				<input class="form-control" type="text" name="importNum" value="${company.importNum!20000}" maxlength="5"/>
			</div>
		</div>
		<div class="form-group form-inline row">
			<div class="col-sm-6">
				<label style="width: 132px;">A&B录音批量下载：</label>
				<label class="radio-inline"><input type="radio" class="minimal" name="taskSoundDownloadEnable" value="0" <#if company?? && company.taskSoundDownloadEnable?? && company.taskSoundDownloadEnable = 0>checked</#if>>&nbsp;&nbsp;不启用</label>
				<label class="radio-inline"><input type="radio" class="minimal" name="taskSoundDownloadEnable" value="1" <#if company?? && company.taskSoundDownloadEnable?? && company.taskSoundDownloadEnable = 1>checked</#if>>&nbsp;&nbsp;启用</label>
			</div>
			<div class="col-sm-6">
				<label style="width: 132px;">通话状态权限控制：</label>
				<#if company.callStateAuthority??>
					<label class="radio-inline"><input type="radio" class="minimal" name="callStateAuthority" value="0" <#if company?? && company.callStateAuthority?? && company.callStateAuthority = 0>checked</#if>>&nbsp;&nbsp;没有权限</label>
					<label class="radio-inline"><input type="radio" class="minimal" name="callStateAuthority" value="1" <#if company?? && company.callStateAuthority?? && company.callStateAuthority = 1>checked</#if>>&nbsp;&nbsp;有权限</label>
				<#else>
					<label class="radio-inline"><input type="radio" class="minimal" name="callStateAuthority" value="0" checked>&nbsp;&nbsp;没有权限</label>
					<label class="radio-inline"><input type="radio" class="minimal" name="callStateAuthority" value="1" >&nbsp;&nbsp;有权限</label>
				</#if>
			</div>
		</div>
		<div class="form-group form-inline row">
			<div class="col-sm-6">
				<label style="width: 132px;">话术免审：</label>
				<#if company.specialPower??>
					<label class="radio-inline"><input type="radio" class="minimal" name="specialPower" value="0" <#if company?? && company.specialPower?? && company.specialPower = 0>checked</#if>>&nbsp;&nbsp;不启用</label>
					<label class="radio-inline"><input type="radio" class="minimal" name="specialPower" value="1" <#if company?? && company.specialPower?? && company.specialPower = 1>checked</#if>>&nbsp;&nbsp;启用</label>
				<#else>
					<label class="radio-inline"><input type="radio" class="minimal" name="specialPower" value="0" checked>&nbsp;&nbsp;不启用</label>
					<label class="radio-inline"><input type="radio" class="minimal" name="specialPower" value="1" >&nbsp;&nbsp;启用</label>
				</#if>
			</div>
			<div class="col-sm-6">
				<label style="width: 132px;">话术方言支持：</label>
				<#if company.supportDialect??>
					<label class="radio-inline"><input type="radio" class="minimal" name="supportDialect" value="0" <#if company?? && company.supportDialect?? && company.supportDialect = 0>checked</#if>>&nbsp;&nbsp;不启用</label>
					<label class="radio-inline"><input type="radio" class="minimal" name="supportDialect" value="1" <#if company?? && company.supportDialect?? && company.supportDialect = 1>checked</#if>>&nbsp;&nbsp;启用</label>
				<#else>
					<label class="radio-inline"><input type="radio" class="minimal" name="supportDialect" value="0" checked>&nbsp;&nbsp;不启用</label>
					<label class="radio-inline"><input type="radio" class="minimal" name="supportDialect" value="1" >&nbsp;&nbsp;启用</label>
				</#if>
			</div>
		</div>
		<div class="form-group form-inline row">
			<div class="col-sm-6">
				<label style="width: 132px;">支持大数据：</label>
				<#if company.supportBigData??>
					<label class="radio-inline"><input type="radio" class="minimal" name="supportBigData" value="0" <#if company?? && company.supportBigData?? && company.supportBigData = 0>checked</#if>>&nbsp;&nbsp;不启用</label>
					<label class="radio-inline"><input type="radio" class="minimal" name="supportBigData" value="1" <#if company?? && company.supportBigData?? && company.supportBigData = 1>checked</#if>>&nbsp;&nbsp;启用</label>
				<#else>
					<label class="radio-inline"><input type="radio" class="minimal" name="supportBigData" value="0" checked>&nbsp;&nbsp;不启用</label>
					<label class="radio-inline"><input type="radio" class="minimal" name="supportBigData" value="1" >&nbsp;&nbsp;启用</label>
				</#if>
			</div>
			<div class="col-sm-6">
				<label><span style="color: red">*</span>公司员工限制:</label>
				<input class="form-control" type="number" min="1" max="9999" name="employeeMaxNum" value="${company.employeeMaxNum!1}" style="width: 130px;" required />
			</div>
		</div>
		<div class="form-group form-inline row">
			<div class="col-sm-12">
				<label style="width: 132px;">权限控制：</label>
                <select class="form-control select2" multiple="multiple" data-placeholder="选择权限控制"  style="width: 520px;" name="authorityControls">
					<#list authorityControlMap as k,v>
						<option value="${k}" <#if authorityControl?? && authorityControl.authorities?seq_contains(k)>selected</#if> >${v}</option>
					</#list>
                </select>
			</div>
		</div>
		
		<h4 style="padding: 20px 0;border-bottom: 1px solid #e5e5e5">管理员账号：</h4>
		<div class="form-group form-inline row">
			<div class="col-sm-6">
			<label><span style="color: red">*</span>管理员姓名：</label> <input class="form-control" type="text"
				name="userName" value="${user.userName!}" maxlength="50" />
			</div>
			<div class="col-sm-6">
			<label><span style="color: red">*</span>登录名：</label> <input class="form-control" type="text"
				name="loginName" value="${user.loginName!}" maxlength="50" />
			</div>
		</div>
		<div class="form-group form-inline row">
			<div class="col-sm-6">
			<label><span style="color: red">*</span>联系电话：</label> <input class="form-control" type="text"
				name="phone" value="${user.phone!}" maxlength="50" required />
			</div>
		</div>
</form>

<script>
	$("#addCompany").validate({
        rules: {
        	importNum : {
        		digits : true,
        		max : 50000,
        		min : 1
            },
            userName : {
            	trimRequired : true,
            	unContainSpace : true
            },
            loginName : {
            	trimRequired : true,
            	unContainSpace : true,
            	loginNameUnique : true
            },
            companyName : {
            	trimRequired : true,
            	unContainSpace : true,
            	companyNameUnique : true
            }
        },
        messages: {
        	importNum: {
        		digits : "该字段必须是正整数",
        		max : "该字段不能大于50000",
        		min : "该字段不能小于1"
            }/* ,
            userName : {
            	trimRequired : "该字段不能为空"
            },
            loginName : {
            	trimRequired : "该字段不能为空"
            } */
        }
	});
	$.validator.addMethod("trimRequired", function(value, element) {
		if (value == '') {
			return false;
		}
		if ($.trim(value) == '') {
			return false;
		}
		return true;
	}, "该字段不能为空");
	$.validator.addMethod("unContainSpace", function(value, element) {
		if (value == '' || $.trim(value) == '') {
			return true;
		}
		if ($.trim(value).search(/\s/) != -1) {
			return false;
		}
		return true;
	}, "该字段不能包含空格");
	$.validator.addMethod("loginNameUnique", function(value, element) {
		var userId = $("input[name='userId']").val();
		userId = userId ? userId : '';
		var loginName = $.trim(value);
		// console.log('userId=' + userId + ', loginName='+loginName);
		
		var verificationPassed = false;
		$.ajax({
			url : "${ctx}/userinfo/verifyLoginNameUnique",
			type : 'post',
			dataType : 'json',
			async : false,
			data : {"userId" : userId, "loginName" : loginName},
			success : function(data) {
				if (data.result == 'success') {
					verificationPassed = true;
				}
			}
		});
		
		return verificationPassed;
	}, "登录名不能重复");
	$.validator.addMethod("companyNameUnique", function(value, element) {
		var companyId = $("input[name='companyId']").val();
		companyId = companyId ? companyId : '';
		var companyName = $.trim(value);
		// console.log('companyId=' + companyId + ', companyName='+companyName);
		
		var verificationPassed = false;
		$.ajax({
			url : "${ctx}/company/verifyCompanyNameUnique",
			type : 'post',
			dataType : 'json',
			async : false,
			data : {"companyId" : companyId, "companyName" : companyName},
			success : function(data) {
				console.log('result=' + data.result );
				if (data.result == 'success') {
					verificationPassed = true;
				}
			}
		});
		
		return verificationPassed;
	}, "公司名称不能重复");
	
	$('.select2').select2();
	$.fn.modal.Constructor.prototype.enforceFocus = function() {};
	
	$("select[name='provinceCode']").change(function(){
		var provinceCode = $(this).val();
		$.ajax({
			url:"${ctx}/area/getCity?provinceCode="+provinceCode,
			dataType:"json",
			success:function(res){
				var citys = res.data;
				console.log(citys);
				$("#cityCode").find("option").remove();
				$("#cityCode").append("<option value=''>--请选择--</option>");
				for(var i=0; i<citys.length; i++){
					$("#cityCode").append("<option value='"+citys[i].code+"'>"+citys[i].city+"</option>");
				}
			}
		})
	});
	
	$("select[name='agentsId']").change(function(){
		var agentsName = $(this).find("option:selected").text();
		$("input[name='agentsName']").val(agentsName);
	});
	
	$("select[name='saleId']").change(function() {
		var saleName = $(this).find("option:selected").text();
		$("input[name='saleName']").val(saleName);
	});
	
	$("select[name='accountManagerId']").change(function() {
		var accountManagerName = $(this).find("option:selected").text();
		$("input[name='accountManagerName']").val(accountManagerName);
	});
	
	$('#expirationTime').datepicker({
        autoclose: true,
        format: 'yyyy-mm-dd',
        language: 'zh-CN'
    });
	
	//iCheck for checkbox and radio inputs
    $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
      checkboxClass: 'icheckbox_minimal-blue',
      radioClass   : 'iradio_minimal-blue'
    });
</script>
<#recover>
  错误
</#attempt>
